package com.macro.task;

import com.macro.mapper.UiGoodsSkuMapper;
import com.macro.pojos.pojo.UiGoodsSkuStock;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
@Slf4j
public class TimerTask {

    @Autowired
    UiGoodsSkuMapper uiGoodsSkuMapper;

    /**
     * 库存预警
     */
    @Scheduled(cron = "*/1 * * * * ?")
    private List<String> InventoryAlert() {
        List<UiGoodsSkuStock> uiGoodsSkuList = uiGoodsSkuMapper.selectList(null);
        List<String> warning = new ArrayList<>();
        for (UiGoodsSkuStock uiGoodsSku : uiGoodsSkuList) {
            if (uiGoodsSku.getLowStock() != null){
                if (uiGoodsSku.getStock()<=uiGoodsSku.getLowStock()){
                    String str = "库存不足==>货号:"+uiGoodsSku.getGoodsSn()+",sku编号:"+uiGoodsSku.getSkuCode();
                    warning.add(str);
                    log.info(str);
                }
            }
        }
        return warning;
    }

}
